package com.gogant.spider.core;

import java.net.Proxy;
import java.net.URL;
import java.net.URLConnection;

public interface Connector<Sp extends Spider<Req, Resp, Conn>, Req extends Request, Resp extends Response, Conn extends URLConnection> {

	/**
	 * 根据URL创建Request请求
	 * @param url
	 * @return
	 * @throws SpiderException
	 */
	Req createRequest(URL url) throws SpiderException;

	/**
	 * 根据URL和代理打开URL连接
	 * @param url
	 * @param proxy
	 * @return
	 * @throws SpiderException
	 */
	Conn openConnection(URL url, Proxy proxy) throws SpiderException;

	/**
	 * 处理URL连接，并返回响应结果
	 * @param spider
	 * @param req
	 * @param conn
	 * @return
	 * @throws SpiderException
	 */
	Resp handleConnection(Sp spider, Req req, Conn conn) throws SpiderException;

	/**
	 * 销毁此Connector
	 * @throws SpiderException
	 */
	void destroy() throws SpiderException;

}
